package org.yray.io.gcdemo;

import com.alibaba.fastjson.JSONObject;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryManagerMXBean;
import java.util.List;

/**
 * @author lyg
 * @date 2021/9/25 21:16
 * -XX:+UseG1GC -XX:+PrintGCDetails
 * -XX:+UseShenandoahGC -XX:+PrintGCDetails
 */
public class GcCollectorPrinter {
    public static void main(String[] args) {
        print(ManagementFactory.getGarbageCollectorMXBeans());
        //print(ManagementFactory.getMemoryPoolMXBeans());
        print(ManagementFactory.getMemoryManagerMXBeans());
        print(ManagementFactory.getMemoryMXBean());
        print(ManagementFactory.getThreadMXBean());
        print(ManagementFactory.getRuntimeMXBean());
        print(ManagementFactory.getCompilationMXBean());
        print(ManagementFactory.getClassLoadingMXBean());
        print(ManagementFactory.getOperatingSystemMXBean());
    }

    private static void print(List list)
    {
        for (Object obj : list) {
            System.out.println(JSONObject.toJSONString(obj));
        }
        System.out.println("------------------------------------------------");
    }

    private static void print(Object obj)
    {
        System.out.println(JSONObject.toJSONString(obj));
        System.out.println("------------------------------------------------");
    }
}
